/**
 * The Prophecy
 * java based lightweight texas hold'em poker software base
 * http://code.google.com/p/theprophecy/
 */

package org.poker.prophecy.simulation.demo;

import java.util.Vector;

import org.poker.prophecy.core.Card;
import org.poker.prophecy.core.CardDeck;
import org.poker.prophecy.core.CardVectorTools;
import org.poker.prophecy.core.PocketCards;
import org.poker.prophecy.core.PokerHand;
import org.poker.prophecy.core.WinnerDeterminer;
import org.poker.prophecy.player.general.Player;
import org.poker.prophecy.player.preflopstyles.StartingHandsAnalysisSamBraids;
import org.poker.prophecy.player.primitiv.CheckerPlayer;
import org.poker.prophecy.simulation.Table;

/**
 * @author bg
 */

public class DemoGame {

    public DemoGame(){
        Vector<Player> playaz = new Vector<Player>();
        Player player1 = new CheckerPlayer("Berni", 1000, null); 
        Player player2 = new CheckerPlayer("Tusek", 1000, null);
        Player player3 = new CheckerPlayer("Flavio", 1000, null);
        Player player4 = new CheckerPlayer("Alex", 1000, null);
        
        playaz.addElement(player1);
        playaz.addElement(player2);
        playaz.addElement(player3);
        playaz.addElement(player4);
        
        Table table = new Table(playaz);
        table.setVectorIndexOfDealerButton(0);//Berni ist Dealer
        
        CardDeck deck = null;
        Vector<Card> flop = new Vector<Card>();
        Card turn = null;
        Card river = null;
        deck = new CardDeck();
        deck.shuffleDeck();
        flop.addElement(deck.getCardsInDeck().elementAt(0));
        flop.addElement(deck.getCardsInDeck().elementAt(1));
        flop.addElement(deck.getCardsInDeck().elementAt(2));
        turn = deck.getCardsInDeck().elementAt(3);
        river = deck.getCardsInDeck().elementAt(4);
        
        PocketCards p1pocket = new PocketCards(deck.getCardsInDeck().elementAt(5), deck.getCardsInDeck().elementAt(6));
        PocketCards p2pocket = new PocketCards(deck.getCardsInDeck().elementAt(7), deck.getCardsInDeck().elementAt(8));
        PocketCards p3pocket = new PocketCards(deck.getCardsInDeck().elementAt(9), deck.getCardsInDeck().elementAt(10));
        PocketCards p4pocket = new PocketCards(deck.getCardsInDeck().elementAt(11), deck.getCardsInDeck().elementAt(12));
        player1.setPocketCards(p1pocket);
        player2.setPocketCards(p2pocket);
        player3.setPocketCards(p3pocket);
        player4.setPocketCards(p4pocket);
        
        Vector<Card> p1Seven = new Vector<Card>();
        p1Seven.addElement(p1pocket.getCard1());
        p1Seven.addElement(p1pocket.getCard2());
        p1Seven.addAll(flop);
        p1Seven.add(river);
        p1Seven.add(turn);
        PokerHand p1Hand = CardVectorTools.getBestHandFromSevenCardsVector(p1Seven);
        
        Vector<Card> p2Seven = new Vector<Card>();
        p2Seven.addElement(p2pocket.getCard1());
        p2Seven.addElement(p2pocket.getCard2());
        p2Seven.addAll(flop);
        p2Seven.add(river);
        p2Seven.add(turn);
        PokerHand p2Hand = CardVectorTools.getBestHandFromSevenCardsVector(p2Seven);
        
        Vector<Card> p3Seven = new Vector<Card>();
        p3Seven.addElement(p3pocket.getCard1());
        p3Seven.addElement(p3pocket.getCard2());
        p3Seven.addAll(flop);
        p3Seven.add(river);
        p3Seven.add(turn);
        PokerHand p3Hand = CardVectorTools.getBestHandFromSevenCardsVector(p3Seven);

        Vector<Card> p4Seven = new Vector<Card>();
        p4Seven.addElement(p4pocket.getCard1());
        p4Seven.addElement(p4pocket.getCard2());
        p4Seven.addAll(flop);
        p4Seven.add(river);
        p4Seven.add(turn);
        PokerHand p4Hand = CardVectorTools.getBestHandFromSevenCardsVector(p4Seven);
        
        Vector<PokerHand> handsVector = new Vector<PokerHand>();
        handsVector.addElement(p1Hand);
        handsVector.addElement(p2Hand);
        handsVector.addElement(p3Hand);
        handsVector.addElement(p4Hand);
        WinnerDeterminer wd = new WinnerDeterminer(handsVector);
        
        System.out.println("Flop ist "+flop+", Turn ist "+turn+", River ist "+river);
        System.out.println("P1-Pocket: "+p1pocket+" "+StartingHandsAnalysisSamBraids.getStartingHandRatingAsPrintableString(playaz.elementAt(0).getPocketCards())+" mit Hand "+p1Hand+" mit Rank "+wd.getCategoryNumberForHand(p1Hand)+" "+p1Hand.getHandRankAsPrintableString());
        System.out.println("P2-Pocket: "+p2pocket+" "+StartingHandsAnalysisSamBraids.getStartingHandRatingAsPrintableString(playaz.elementAt(1).getPocketCards())+" mit Hand "+p2Hand+" mit Rank "+wd.getCategoryNumberForHand(p2Hand)+" "+p2Hand.getHandRankAsPrintableString());
        System.out.println("P3-Pocket: "+p3pocket+" "+StartingHandsAnalysisSamBraids.getStartingHandRatingAsPrintableString(playaz.elementAt(2).getPocketCards())+" mit Hand "+p3Hand+" mit Rank "+wd.getCategoryNumberForHand(p3Hand)+" "+p3Hand.getHandRankAsPrintableString());
        System.out.println("P4-Pocket: "+p4pocket+" "+StartingHandsAnalysisSamBraids.getStartingHandRatingAsPrintableString(playaz.elementAt(3).getPocketCards())+" mit Hand "+p4Hand+" mit Rank "+wd.getCategoryNumberForHand(p4Hand)+" "+p4Hand.getHandRankAsPrintableString());
        System.out.println("Es gibt "+wd.getWinners().size()+" Sieger mit "+wd.getWinners().elementAt(0).getHandRankAsPrintableString());
        System.out.println("********************************************************");
      
    }
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            System.out.println("************** Spiel Nr. "+i+"****************");
            new DemoGame();
        }
        
        
    }

}
